﻿using System.Collections.ObjectModel;
using Caliburn.Micro;
using JY.Wpf.Core.ViewModelBases;
using JY.Wpf.Test.Views.ControlDemoViews;
using SD.IOC.Core.Mediators;

namespace JY.Wpf.Test.ViewModels.ControlDemoViewModels
{
    /// <summary>
    /// TreeListViewDemo
    /// </summary>
    public class TreeListViewDemoViewModel : ViewModelBase
    {
        #region # 变量

        private ObservableCollection<Staff> _StaffList = new ObservableCollection<Staff>();
        private bool _isFlipped1;
        public ObservableCollection<Staff> StaffList
        {
            get { return _StaffList; }
            set
            {
                _StaffList = value;
                this.NotifyOfPropertyChange();
            }
        }
        #endregion

        #region # 构造器
        /// <summary>
        /// 构造器
        /// </summary>
        public TreeListViewDemoViewModel()
        {
            IsFlipped1 = true;
            Staff staff = new Staff()
            {
                Name = "张三",
                Age = 30,
                Sex = "男",
                Duty = "经理",
                IsExpanded = true
            };
            Staff staff2 = new Staff()
            {
                Name = "张三1",
                Age = 21,
                Sex = "男",
                Duty = "员工",
                IsExpanded = true
            };
            Staff staff3 = new Staff()
            {
                Name = "张三11",
                Age = 21,
                Sex = "男",
                Duty = "员工"
            };

            staff2.StaffList2.Add(staff3);
            staff3 = new Staff()
            {
                Name = "张三22",
                Age = 21,
                Sex = "女",
                Duty = "员工"
            };
            staff2.StaffList2.Add(staff3);

            staff.StaffList2.Add(staff2);
            staff2 = new Staff()
            {
                Name = "张三2",
                Age = 22,
                Sex = "女",
                Duty = "员工"
            };
            staff.StaffList2.Add(staff2);
            staff2 = new Staff()
            {
                Name = "张三3",
                Age = 23,
                Sex = "女",
                Duty = "员工"
            };
            staff.StaffList2.Add(staff2);
            StaffList.Add(staff);

            staff = new Staff()
            {
                Name = "李四",
                Age = 31,
                Sex = "男",
                Duty = "副经理"
            };
            staff2 = new Staff()
            {
                Name = "李四1",
                Age = 24,
                Sex = "女",
                Duty = "员工"
            };
            staff.StaffList2.Add(staff2);
            staff2 = new Staff()
            {
                Name = "李四2",
                Age = 25,
                Sex = "女",
                Duty = "员工"
            };
            staff.StaffList2.Add(staff2);
            staff2 = new Staff()
            {
                Name = "李四3",
                Age = 26,
                Sex = "男",
                Duty = "员工"
            };
            staff.StaffList2.Add(staff2);
            StaffList.Add(staff);

            staff = new Staff()
            {
                Name = "王五",
                Age = 32,
                Sex = "女",
                Duty = "组长"
            };
            staff2 = new Staff()
            {
                Name = "王五1",
                Age = 27,
                Sex = "女",
                Duty = "员工"
            };
            staff.StaffList2.Add(staff2);
            staff2 = new Staff()
            {
                Name = "王五2",
                Age = 28,
                Sex = "女",
                Duty = "员工"
            };
            staff.StaffList2.Add(staff2);
            StaffList.Add(staff);
        }
        #endregion

        #region # 属性
        public bool IsFlipped1
        {
            get { return this._isFlipped1; }
            set { this._isFlipped1 = value;base.NotifyOfPropertyChange(); }
        }
        #endregion

        #region # Command方法

        public void GetSelected(Staff staff)
        {
            //MessageBox.Show(staff.Name, "提示信息");
            IsFlipped1 = false;
        }

        #endregion

        #region # 方法

        #endregion

        #region # 获取页面 —— object GetView(object context = null)
        /// <summary>
        /// 获取页面
        /// </summary>
        /// <param name="context">页面</param>
        /// <returns></returns>
        public override object GetView(object context = null)
        {
            return ResolveMediator.Resolve<TreeListViewDemoView>();
        }
        #endregion
    }

    public class Staff :PropertyChangedBase
    {
        private string _Name;
        private int _Age;
        private string _Sex;
        private string _Duty;
        private bool _IsSelected;
        private bool _IsExpanded;

        private ObservableCollection<Staff> _StaffList = new ObservableCollection<Staff>();

        public ObservableCollection<Staff> StaffList2
        {
            get { return _StaffList; }
            set
            {
                _StaffList = value;
                this.NotifyOfPropertyChange("StaffList");
            }
        }

        /// <summary>
        /// 姓名
        /// </summary>
        public string Name
        {
            get { return _Name; }
            set
            {
                _Name = value;
                this.NotifyOfPropertyChange("Name");
            }
        }
        /// <summary>
        /// 年龄
        /// </summary>
        public int Age
        {
            get { return _Age; }
            set
            {
                _Age = value;
                this.NotifyOfPropertyChange("Age");
            }
        }
        /// <summary>
        /// 性别
        /// </summary>
        public string Sex
        {
            get { return _Sex; }
            set
            {
                _Sex = value;
                this.NotifyOfPropertyChange("Sex");
            }
        }
        /// <summary>
        /// 职务
        /// </summary>
        public string Duty
        {
            get { return _Duty; }
            set
            {
                _Duty = value;
                this.NotifyOfPropertyChange("Duty");
            }
        }

        /// <summary>
        /// 是否选中
        /// </summary>
        public bool IsSelected
        {
            get { return _IsSelected; }
            set
            {
                _IsSelected = value;
                this.NotifyOfPropertyChange("IsSelected");
            }
        }
        /// <summary>
        /// 是否展开
        /// </summary>
        public bool IsExpanded
        {
            get { return _IsExpanded; }
            set
            {
                _IsExpanded = value;
                this.NotifyOfPropertyChange("IsExpanded");
            }
        }

        public Staff()
        {
            IsSelected = false;
            IsExpanded = false;
        }
    }
}
